﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wozuji.Logic.Users;

public partial class userlogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
          //  Wozuji.Logic.Users.Users ur = new Wozuji.Logic.Users.Users();



            Session.Remove("userid");
            Label1.Text = "";
            string userName, passWord;
            userName = username.Text.ToString();
            passWord = password.Text.ToString();
            bool islogin;
            islogin = issave.Checked;
            Users ur = new Users();





            //判断用户的输入
            if (userName.Equals("") || passWord.Equals(""))
            {
                Label1.Text = "用户名或密码不能为空,请检查你的输入!";
            }
            //输入无问题,开始登录
            else
            {

                if (ur.userLogin(userName, passWord, islogin))
                {

                    
                    //判断用户是否是有需要加入的组群信息
                    Wozuji.Logic.groups gp = new Wozuji.Logic.groups();
                    int gpid=gp.getInviteGroupId();
                    if (gpid> 0)
                    {
                        
                        if (gp.joinGroup(gpid, Convert.ToInt32(Session["userid"].ToString())))
                        {
                            gp.removeInviteGroupId();
                            Wozuji.Common.MessageBox.ShowAndRedirect(Page, "加入组群成功!", "/groups/default.aspx");
                        }
                        else
                        {
                            Response.Redirect("/user/default.aspx");
                        }
                    
                    }
                    else
                    {
                        Response.Redirect("/user/default.aspx");
                    }


                }
                else
                {
                    Label1.Text = "登录失败,用户名或密码错误!";
                }
            }
        }
    }
    protected void username_TextChanged(object sender, EventArgs e)
    {

    }
}

